package mis.ds.ps.model.obj;

import java.io.Serializable;
import java.util.Collections;
import java.util.Map;
import java.util.WeakHashMap;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import mis.ds.ps.model.iface.IHorarios;

import org.hibernate.proxy.HibernateProxy;

import com.felees.hbnpojogen.persistence.IPojoGenEntity;


/** 
 * Object mapping for hibernate-handled table: horarios.
 * @author autogenerated
 */

@Entity
@Table(name = "horarios", catalog = "initial_timetable")
public class Horarios implements Cloneable, Serializable, IPojoGenEntity, IHorarios {

	/** Serial Version UID. */
	private static final long serialVersionUID = -558994946L;

	/** Use a WeakHashMap so entries will be garbage collected once all entities 
		referring to a saved hash are garbage collected themselves. */
	private static final Map<Serializable, Long> SAVED_HASHES =
		Collections.synchronizedMap(new WeakHashMap<Serializable, Long>());
	
	/** hashCode temporary storage. */
	private volatile Long hashCode;
	

	/** Field mapping. */
	private Long id = 0L; // init for hibernate bug workaround
	/** Field mapping. */
	private String nome;
	/** Field mapping. */
	private Long versao;
	/** Field mapping. */
	private Integer version;
	/**
	 * Default constructor, mainly for hibernate use.
	 */
	public Horarios() {
		// Default constructor
	} 

	/** Constructor taking a given ID.
	 * @param id to set
	 */
	public Horarios(Long id) {
		this.id = id;
	}
	
 


 
	/** Return the type of this class. Useful for when dealing with proxies.
	* @return Defining class.
	*/
	@Transient
	public Class<?> getClassType() {
		return Horarios.class;
	}
 

    /**
     * Return the value associated with the column: id.
	 * @return A Long object (this.id)
	 */
    @Id 
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column( name = "id", nullable = false  )
	public Long getId() {
		return this.id;
		
	}
	

  
    /**  
     * Set the value related to the column: id.
	 * @param id the id value you wish to set
	 */
	public void setId(final Long id) {
		// If we've just been persisted and hashCode has been
		// returned then make sure other entities with this
		// ID return the already returned hash code
		if ( (this.id == null || this.id == 0L) &&
				(id != null) &&
				(this.hashCode != null) ) {
			SAVED_HASHES.put( id, this.hashCode );
		}
		this.id = id;
	}

    /**
     * Return the value associated with the column: nome.
	 * @return A String object (this.nome)
	 */
	@Column( length = 256  )
	public String getNome() {
		return this.nome;
		
	}
	

  
    /**  
     * Set the value related to the column: nome.
	 * @param nome the nome value you wish to set
	 */
	public void setNome(final String nome) {
		this.nome = nome;
	}

    /**
     * Return the value associated with the column: versao.
	 * @return A Long object (this.versao)
	 */
	public Long getVersao() {
		return this.versao;
		
	}
	

  
    /**  
     * Set the value related to the column: versao.
	 * @param versao the versao value you wish to set
	 */
	public void setVersao(final Long versao) {
		this.versao = versao;
	}

    /**
     * Return the value associated with the column: version.
	 * @return A Integer object (this.version)
	 */
	public Integer getVersion() {
		return this.version;
		
	}
	

  
    /**  
     * Set the value related to the column: version.
	 * @param version the version value you wish to set
	 */
	public void setVersion(final Integer version) {
		this.version = version;
	}


   /**
    * Deep copy.
	* @return cloned object
	* @throws CloneNotSupportedException on error
    */
    @Override
    public Horarios clone() throws CloneNotSupportedException {
		
        final Horarios copy = (Horarios)super.clone();

		copy.setId(this.getId());
		copy.setNome(this.getNome());
		copy.setVersao(this.getVersao());
		copy.setVersion(this.getVersion());
		return copy;
	}
	


	/** Provides toString implementation.
	 * @see java.lang.Object#toString()
	 * @return String representation of this class.
	 */
	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		
		sb.append("id: " + this.getId() + ", ");
		sb.append("nome: " + this.getNome() + ", ");
		sb.append("versao: " + this.getVersao() + ", ");
		sb.append("version: " + this.getVersion());
		return sb.toString();		
	}


	/** Equals implementation. 
	 * @see java.lang.Object#equals(java.lang.Object)
	 * @param aThat Object to compare with
	 * @return true/false
	 */
	@Override
	public boolean equals(final Object aThat) {
		Object proxyThat = aThat;
		
		if ( this == aThat ) {
			 return true;
		}

		
		if (aThat instanceof HibernateProxy) {
 			// narrow down the proxy to the class we are dealing with.
 			try {
				proxyThat = ((HibernateProxy) aThat).getHibernateLazyInitializer().getImplementation(); 
			} catch (org.hibernate.ObjectNotFoundException e) {
				return false;
		   	}
		}
		if (aThat == null)  {
			 return false;
		}
		
		final Horarios that; 
		try {
			that = (Horarios) proxyThat;
			if ( !(that.getClassType().equals(this.getClassType()))){
				return false;
			}
		} catch (org.hibernate.ObjectNotFoundException e) {
				return false;
		} catch (ClassCastException e) {
				return false;
		}
		
		
		boolean result = true;
		result = result && (((this.getId() == null) && ( that.getId() == null)) || (this.getId() != null  && this.getId().equals(that.getId())));
		result = result && (((getNome() == null) && (that.getNome() == null)) || (getNome() != null && getNome().equals(that.getNome())));
		result = result && (((getVersao() == null) && (that.getVersao() == null)) || (getVersao() != null && getVersao().equals(that.getVersao())));
		result = result && (((getVersion() == null) && (that.getVersion() == null)) || (getVersion() != null && getVersion().equals(that.getVersion())));
		return result;
	}
	
	/** Calculate the hashcode.
	 * @see java.lang.Object#hashCode()
	 * @return a calculated number
	 */
	@Override
	public int hashCode() {
		if ( this.hashCode == null ) {
			synchronized ( this ) {
				if ( this.hashCode == null ) {
					Long newHashCode = null;

					if ( getId() != null ) {
						newHashCode = SAVED_HASHES.get( getId() );
					}
					
					if ( newHashCode == null ) {
						if ( getId() != null && getId() != 0L) {
							newHashCode = getId();
						} else {
							newHashCode = (long) super.hashCode();

						}
					}
					
					this.hashCode = newHashCode;
				}
			}
		}
		return (int) (this.hashCode & 0xffffff);
	}
	

	
}
